﻿using NOVA.AderTemplates;
using System.Collections.Generic;

namespace Common
{
    /// <summary>
    /// 模板引擎帮助类（基于AderTemplates）
    /// </summary>
    public class TemplateHelper
    {
        /// <summary>
        /// 运行模板
        /// </summary>
        /// <param name="templateAbsolutePath">模板绝对路径</param>
        /// <param name="assignParam">模板赋值参数</param>
        /// <returns></returns>
        public static string RunTemplate(string templateAbsolutePath, Dictionary<string, object> assignParam)
        {
            string result = "";

            TemplateManager manager = TemplateManager.FromFile(templateAbsolutePath);//可能不好用，可以用FromString
            foreach (var param in assignParam)
            {
                manager.SetValue(param.Key, param.Value);
            }
            result = manager.Process().Trim();

            return result;
        }
    }
}
